function test() {
    var arr = []
    for (let  i = 0; i < 10; i++) {
      arr[i] = function () {
        console.log(i);
      }
    }
    return arr
  }
  
  
  
  var myArr = test() // [function(){}, ...]
  // myArr[0]()
  // myArr[1]()
  for (var j = 0; j < 10; j++) {
    myArr[j]()
  }